"""
@author: Kenneth Tse  xie.kenneth@gmail.com
"""
import socketserver

class ThreadTcpServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
    pass

class ThreadUdpServer(socketserver.ThreadingMixIn, socketserver.UDPServer):
    pass


def createServer(HOST, PORT, requestHandler, protocol = "tcp", threaded = True):
    if (protocol.lower() == "tcp" and threaded == True):
        return ThreadTcpServer((HOST, PORT), requestHandler)
    if (protocol.lower() == "udp" and threaded == True):
        return ThreadUdpServer((HOST, PORT), requestHandler)
    assert False